package com.gimi.cloud.jimi.client.service.home.impl;

import java.util.HashMap;
import java.util.Map;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import com.gimi.cloud.jimi.client.service.home.AuthenticationStepService;
import com.gimi.cloud.jimi.client.service.userInfo.BankCardService;
import com.gimi.cloud.jimi.client.service.userInfo.EmergencyContactService;
import com.gimi.cloud.jimi.client.service.userInfo.MoreInfoService;
import com.gimi.cloud.jimi.client.service.userInfo.RdFaceInfoService;
import com.gimi.cloud.jimi.client.service.userInfo.RdJxlService;
import com.gimi.cloud.jimi.client.service.userInfo.UserInfoService;
import com.gimi.cloud.jimi.client.service.userInfo.WorkInfoService;
import com.gimi.cloud.jimi.common.enums.ResponseCodeEnum;
import com.gimi.cloud.jimi.common.exception.MsgException;

@Service
public class AuthenticationStepServiceImpl implements AuthenticationStepService {

	@Autowired
	private UserInfoService userInfoService;
	@Autowired
	private RdFaceInfoService rdFaceInfoService;
	@Autowired
	private BankCardService bankCardService;
	@Autowired
	private WorkInfoService workInfoService;
	@Autowired
	private EmergencyContactService emergencyContactService;
	@Autowired
	private RdJxlService rdJxlService;
	@Autowired
	private MoreInfoService moreInfoService;

	@Override
	public Map<String, Object> getAuthenticationInfo(Integer page,Integer userId) {
		Map<String, Object> map = new HashMap<>();
		if (1 == page ) {
			map.put("userInfo", userInfoService.getAuthenticationInfo(userId));
			map.put("faceInfo", rdFaceInfoService.getAuthenticationInfo(userId));
			map.put("bankCard", bankCardService.getAuthenticationInfo(userId));
			return map;
		}else
		if (2 == page ) {
			map.put("workInfo", workInfoService.getAuthenticationInfo(userId));
			map.put("emergencyContact", emergencyContactService.getAuthenticationInfo(userId));
			map.put("jxlInfo", rdJxlService.getAuthenticationInfo(userId));
			return map;
		}else
		if (3 == page ) {
			map.put("moreInfo",  moreInfoService.getAuthenticationInfo(userId));
			return map;
		}else {
			throw new MsgException(ResponseCodeEnum.FAILURE, "认证状态步骤异常!");  
		}
	}

	@Override
	public Integer getAuthenticationStatus(Integer userId) {
		Map<String, Object> userInfoMap = userInfoService.getAuthenticationInfo(userId);
		Map<String, Object> BankMap = bankCardService.getAuthenticationInfo(userId);
		Map<String, Object> faceMap = rdFaceInfoService.getAuthenticationInfo(userId);
		//有数据,未过期
		if (!"1".equals(userInfoMap.get("status").toString()) || !"1".equals(BankMap.get("status").toString()) || !"1".equals(faceMap.get("status").toString())) {
			return 1;
		}
		Map<String, Object> workInfoMap = workInfoService.getAuthenticationInfo(userId);
		Map<String, Object> emergencyMap = emergencyContactService.getAuthenticationInfo(userId);
		Map<String, Object> jxlMap = rdJxlService.getAuthenticationInfo(userId);
		if (!"1".equals(workInfoMap.get("status").toString()) || !"1".equals(emergencyMap.get("status").toString()) || !"1".equals(jxlMap.get("status").toString())) {
			return 2;
		}
		Map<String, Object> moreInfoMap = moreInfoService.getAuthenticationInfo(userId);
		if (!"1".equals(moreInfoMap.get("status").toString())) {
			return 3;
		}
		return 0;
	}

}
